package dao

import (
	"database/sql"
	"fmt"
	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/frame/g"
)

type t_house struct {
}
var T_house = t_house{}

func (a *t_house)GetList(where ...string) (list gdb.List,err error) {
	db:=g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_house")
	if len(where)==0{
	}else {
		model = model.Where(where[0])
	}
	res,err:=model.All()
	return res.List(),err
}

func (a *t_house) Save(data interface{}) (res sql.Result,err error) {
	db:=g.DB(g.Cfg().GetString("custom.db_name"))
	res,err = db.Model("t_house").Data(data).Save()
	if err!=nil{
		return res, err
	}else{
		return res,nil
	}
}

func (a *t_house) Delete(id string) (isOk bool,err error) {
	db:=g.DB(g.Cfg().GetString("custom.db_name"))
	_,err = db.Model("t_house").Delete(fmt.Sprintf("id=%s",id))
	if err!=nil{
		return false, err
	}else{
		return true,nil
	}
}